package rs;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import rs.util.StringUtil;

public class JobDescFixer {
	public static JobDescFixer instance = new JobDescFixer();
	
	public static JobDesc fix(JobDesc jobDesc){
		Method method = null;
		try {
			method = JobDescFixer.class.getDeclaredMethod(jobDesc.id, JobDesc.class);
			return (JobDesc)method.invoke(instance, jobDesc);
		} catch (SecurityException e) {
			e.printStackTrace();
			return jobDesc;
		} catch (NoSuchMethodException e) {
			//该type不需要fixer,或漏掉的fix方法,直接返回原传入值
			return jobDesc;
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
			return jobDesc;
		} catch (IllegalAccessException e) {
			e.printStackTrace();
			return jobDesc;
		} catch (InvocationTargetException e) {
			e.printStackTrace();
			return jobDesc;
		}
	}
	
	@SuppressWarnings("unused")
	private JobDesc taobaoke(JobDesc jobDesc){
		String tbUrl = "http://taoke.alimama.com/spreader/gen_auction_code.htm?_tb_token_=${0}&auction_id=${1}";
		String tbId = StringUtil.find(jobDesc.url, "id\\=(\\d+)");
		String tbKey = "5ee583f64dr31";
		jobDesc.url = StringUtil.format$(tbUrl, tbKey, tbId);
		
		return jobDesc;
	}
	
	public static void main(String[] args) {
		String tbUrl = "http://taoke.alimama.com/spreader/gen_auction_code.htm?_tb_token_=${0}&auction_id=${1}";
		String tbId = StringUtil.find("http://item.taobao.com:80/item.htm?id=3990702644", "id\\=(\\d+)");
		
		System.out.println("Taobao id: " + tbId);
		
		String tbKey = "5ee583f64dr31";
		String r = StringUtil.format$(tbUrl, tbKey, tbId);
		System.out.println(r);
	}
}
